/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

struct kDataView;

class kGraphics;
class kImage;
class kMesh2DBase;
class kView;
class kStream;
class kEffect;
class kMaterial;
class kWindow;
class kImageCache;
class kFont;

#include "kcomponent.h"
#include "kmath.h"
#include "keimageoptions.h"
#include "ksharedresources.h"

class kGraphics : public kComponent {
protected:
	kView* _currentView;
	kImageCache* _imageCache;
	kSharedResources<kFont>* _sharedFonts;
	kSharedResources<kImage>* _sharedImages;

	inline kGraphics() {
		_currentView = 0;
		_imageCache = 0;
		_sharedFonts = 0;
		_sharedImages = 0;
	}

public:
	~kGraphics();

	virtual void onAttached(kEngine* engine);
	virtual void onDetached(kEngine* engine);
	virtual kImage* getBackBuffer() = 0;
	virtual kEffect* createEffect(kStream* source) = 0;
	// Implementations should use the kImageFile class to decode images
	virtual kImage* createImage(kStream* source, keImageOptions options) = 0;
	virtual kImage* createImage(const kVec2i& size, const kColor& color, keImageOptions options) = 0;
	virtual void deleteImage(kImage* image) = 0;
	virtual void beginRender(kView* view, bool resume = false) = 0;
	virtual void endRender() = 0;
	virtual void renderMesh(kMesh2DBase* mesh) = 0;
	virtual kWindow* getWindow() = 0;
	virtual void flush(const kMaterial* material = 0) = 0;
	inline kView* getCurrentView() {
		return _currentView;
	}

	kImage* createImage(const std::tstring& resourceUri, keImageOptions options);
	kEffect* createEffect(const std::tstring& resourceUri);

	inline kImageCache* getImageCache() {
		return _imageCache;
	}
	inline kSharedResources<kFont>* getSharedFonts() {
		return _sharedFonts;
	}
	inline kSharedResources<kImage>* getSharedImages() {
		return _sharedImages;
	}
};
